<?php
/**
 * author    tangxiaowen
 * mail:     846506584@qq.com
 * Date:     2019/3/11 22:02
 * describe: 基础继承类
 */
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Log;
use think\Db;
class Base extends Controller
{
    public function __construct()
    {
        parent::__construct();
//
//      //验证登陆信息
//      $this->isCheckLogin();
//
//      //初始化本模块下所有日志存放目录
//      $this->initLogSavePath();
    }

    /**
     * 验证登陆信息
     * @param string $token 登陆token
     * @param string $userid 用户ID
     */
    private function isCheckLogin(){

        $action = strtolower(Request::instance()->action());
        $checkLoginData = config('queue.checkLogin');
        if(!in_array($action,$checkLoginData)){
            $header =Request::instance()->header();
            if(!isset($header['userid'])){
				 show_error_api($message='缺少请求参数userid');
            }
            if(!isset($header['token'])){
                 show_error_api($message='缺少请求参数token');
            }
			$user =Db::table('xb_mem_info')->where('ID',$header['userid'])->find();
	        if(!$user){
				 show_error_api($message='该用户不存在');
	        }
	        if($user['token'] !=$header['token']){
	           
				show_error_api($message='登录已过期');
	        }
			$time = time();
	        if($time-$header['token']>604800){
	          
				show_error_api($message='登录已过期');
	        }
        }
    }

    /**
     * 初始化本模块下所有日志存放目录
     */
    private function initLogSavePath()
    {
        $requestName = Request::instance()->module();
        $controllerName = Request::instance()->controller();
        $action = Request::instance()->action();
        $setPath = strtolower("{$requestName}/{$controllerName}/{$action}/");
        Log::init(['path'=>LOG_PATH.$setPath,'type'  => 'file',]);
    }
	
	 /**
     * 风控接口
	  * $userId 2024 我自己的ID
     */
    public function fengkong_jiuwei($userId='')
    {
		$user =Db::table('xb_mem_info')->where('ID',$userId)->find();
//		增加模型判断  魔蝎 还是新颜
		$mobile_operator=Db::table('xb_sys_basicinfo')->value('mobile_operator');
		if($mobile_operator==1){
			$model_name='model_name1';
		}else if($mobile_operator==2){
			$model_name='model_name2';
		}
		$model_name=Db::table('xb_sys_inteparameter')->where(['ParaName'=>$model_name])->value('ParaValue');//模型名称
//		p($model_name);die;
        $fkData['model_name']=$model_name; //模型名
        $fkData['apply_time']=date('Y-m-d H:i:s'); //时间
        $fkData['mobile']= $user['Mobile'];
        $fkData['name']=$user['TrueName'];
        $fkData['idcard']=$user['IDCard'];
		$social = Db::table('xb_renzen_social')->where('UserID',$userId)->find();
        if(!$social){
        	show_error_api($message='获取用户社交数据失败');
        } 
        $phoneList =$social['Phonelist'];
        $phoneList =json_decode($phoneList,1);//该用户的通讯录
        $fkData['user_address']=$social['address'].$social['ad_detail'];
        //紧急联系人
        $fkData['e_contacts'][0]['contact_name']=$social['person_one'];
        $fkData['e_contacts'][0]['contact_phone']=$social['person_one_mobile'];
        $fkData['e_contacts'][1]['contact_name']=$social['person_two'];
        $fkData['e_contacts'][1]['contact_phone']=$social['person_two_mobile'];
        $fkData['contact']=$phoneList;  //手机通讯录
        $dataOrigin = Db::table('xb_moxie_origin')->where('UserID',$userId)->value('OriginData');
        $dataReport = Db::table('xb_moxie_report')->where('UserID',$userId)->value('ReportData');
        $fkData['carrier_data']['mx_raw']=$dataOrigin;
        $fkData['carrier_data']['mx_report']=$dataReport;
        $da = json_encode($fkData,JSON_UNESCAPED_UNICODE);
        $url = 'http://47.93.185.26/risk/gzip/';
        $datas=gzencode($da);
		$realScore =httpPost($datas,$url);
        return $realScore;
      
    }
	
	
	

}